<template>
  <div class="noveldetail">
    <div class="bigbox" v-if="fiction">
      <!-- 头部 -->
      <header>
        <div class="h-left">
          <div @click="back">
            <img src="../../assets/image/18721.png" style="width: 8px" />
          </div>
        </div>
        <div class="h-title">书架详情</div>
        <div class="h-right" style="margin-right: 10px">
          <router-link to="/personal">书架</router-link>
        </div>
      </header>

      <!-- 书籍具体 -->
      <div class="book_specific">
        <div class="book_top">
          <div class="book_img">
            <img :src="fiction.fictionImg + '?param=140y140'" alt="" />
          </div>
          <!-- 介绍 -->
          <div class="infour">
            <div class="in_textone">
              <h1>{{ fiction.titleName }}</h1>
            </div>
            <div class="in_texttwo">{{ fiction.Author }}</div>
            <div class="in_texttwo">
              {{ fiction.state }}(共{{ fiction.chapter }}章)
            </div>
          </div>
          <!-- 收藏 -->
          <span
            :class="color == true ? 'coll' : ''"
            class="iconfont icon-lolxiai collection"
            @click="collection"
          ></span>
        </div>
        <!-- 阅读 -->
        <div class="reading">
          <router-link to="/novelmain" class="reading_btn"
            ><span>免费阅读</span></router-link
          >
        </div>
        <!-- 章节 -->
        <div class="new-book">
          <div class="latest">最新</div>
          <div class="chapter">
            <router-link to="/novelmain">第一章 道友请给五星好评</router-link>
          </div>
          <div class="time_hoe">一个月前</div>
        </div>
        <div class="direc-tory" v-if="!show">
          <header>
            <div class="h-left">
              <img
                @click.stop.prevent="onHide"
                src="../../assets/image/18721.png"
                style="width: 8px"
              />
            </div>
            <div class="h-title">
              仙界聊天群-目录<span class="title-span">（共1892章）</span>
            </div>
            <div class="h-right">
              <router-link
                class="book"
                style="margin-right: 10px"
                to="/personal"
                >书架</router-link
              >
            </div>
          </header>
          <div class="mulu_topmenu" style="padding-bottom: 5px">
            <div class="mulu_select">
              <div class="mule_text">1-7章</div>
              <select name="menulist">
                <option value="1" selected="">1-7章</option>
              </select>
            </div>
            <div class="mulu_order_z" @click="select(1)">反序</div>
            <div class="mulu_order_z" @click="select(2)">正序</div>
          </div>
          <!-- 目录列表 -->
          <div class="mulu_lists" style="margin-top: 5px">
            <div class="list_main book_list">
              <span v-for="(data, index) in flitertitle" :key="index">{{
                data.title
              }}</span>
            </div>
          </div>
        </div>
      </div>
      <!-- 简介 -->
      <div class="mulu_lists">
        <van-tabs type="card">
          <van-tab title="简介">
            <div id="con_one_1" style="text-indent: 2em">
              <div class="janjie">
                <div class="synopsis">{{ fiction.introduce }}</div>
              </div>
            </div>
          </van-tab>
        </van-tabs>
      </div>

      
      <!-- 页脚 -->
      <footermodule></footermodule>
    </div>
  </div>
</template>

<script>
import { getFictionApi } from "../../api/novelmain.js";
import footermodule from "../../components/FooterModule.vue";
import { Toast } from "vant";

export default {
  data() {
    return {
      show: true,
      fiction: null,
      // 收藏
      color: false,
      shoucangLists: [],
      content: null,
    };
  },
  methods: {
    back() {
      this.$router.go(-1);
    },
    getFictionApiFun() {
      getFictionApi({ id: this.$route.query.id }).then((data) => {
        let index = data.fiction.findIndex(
          (item) => item.id == this.$route.query.id
        );
        this.fiction = data.fiction[index];
        console.log(this.fiction);
        let num = 0;
        this.shoucangLists.forEach((item) => {
          if (item.id == this.fiction.id) {
            num++;
          } else {
            return num;
          }
        });
        if (num != 0) {
          this.color = true;
        }
      });
    },
    ///收藏
    collection() {
      if (this.color) {
        this.color = false;
        Toast.success("已取消");
        console.log(this.$route.query.id);
        let a = this.shoucangLists.findIndex(
          (item) => item.id == this.$route.query.id
        );
        this.shoucangLists.splice(a, 1);
        localStorage.setItem("shoucang", JSON.stringify(this.shoucangLists));
      } else {
        this.color = true;
        Toast.success("收藏成功");
        let num = 0;
        this.shoucangLists.forEach((item) => {
          console.log(item.id);
          if (item.id == this.fiction.id) {
            num++;
          } else {
            return num;
          }
        });
        if (num == 0) {
          this.shoucangLists.push(this.fiction);
          window.localStorage.setItem(
            "shoucang",
            JSON.stringify(this.shoucangLists)
          );
        }
      }
    },
  },
  created() {
    if (localStorage.shoucang) {
      this.shoucangLists = JSON.parse(localStorage.getItem("shoucang"));
    }
    // console.log(this.$route.query);
    if ("id" in this.$route.query) {
      this.getFictionApiFun();
    }
    getFictionApi().then((data) => {
      this.content = data.content;
      console.log(data.content);
    });
  },

  components: {
    footermodule,
  },
};
</script>

<style lang="scss" scoped>
.mulu_list {
  padding: 0;
  .book_list {
    // margin-left: 5px;
    // margin-right: 5px;
    // border-bottom: 1px #efefef solid;
    padding-left: 10px;
    span {
      display: block;
      font-size: 14px;
      color: #333;
      -webkit-box-flex: 1;
      overflow: hidden;
      white-space: nowrap;
      text-overflow: ellipsis;
      padding: 10px;
    }
  }
}
.book_specific {
  background-color: #fff;
}
.book_top {
  padding: 15px 10px 15px 10px;
  display: flex;
  position: relative;
}
.book_img {
  width: 80px;
  height: 100px;
  background-color: aqua;
  position: relative;
  img {
    width: 100%;
    height: 100%;
    box-shadow: 3px 3px 7px #8888885e;
  }
  &:before {
    content: "";
    display: block;
    position: absolute;
    top: 0px;
    left: 0px;
    width: 30px;
    height: 30px;
    background: url("../../assets/image/15559.png") no-repeat center;
    background-size: 30px 30px;
  }
}
.infour {
  -webkit-box-flex: 1;
  margin-left: 10px;
  padding-top: 4px;
}
.in_textone {
  padding-right: 15px;
  & > h1 {
    font-size: 16px;
    color: #2e343f;
    padding-bottom: 8px;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    padding-top: 1px;
    font-weight: normal;
  }
}
.in_texttwo {
  font-size: 12px;
  color: #666;
  padding-bottom: 8px;
  margin-top: 5px;
}
/* 收藏 */
.collection {
  position: absolute;
  right: 25px;
  top: 20px;
  color: #999;
}
.coll {
  color: rgb(221, 59, 59);
}
/* 阅读 */
.reading {
  margin: 0px 12px;
  display: flex;
  justify-content: center;
}
.reading_btn {
  display: block;
  height: 32px;
  border: 1px #aaaaaa solid;
  border-radius: 3px;
  text-align: center;
  width: 130px;
  margin: 0px 8px;
  span {
    font-size: 15px;
    color: #555;
    line-height: 32px;
    background: url("../../assets/image/阅读.png") left center no-repeat;
    background-size: 14px 13px;
    padding-left: 20px;
  }
}
.down_btn {
  background: #d3270f;
  height: 34px;
  border-radius: 3px;
  text-align: center;
  -webkit-box-flex: 1;
  margin: 0px 8px;
  span {
    font-size: 15px;
    color: #fff;
    line-height: 34px;
    background: url("../../assets/image/down.png") left center no-repeat;
    background-size: 14px;
    padding-left: 20px;
  }
}
/* 章节 */
.new-book {
  height: 40px;
  border-top: 1px #efefef solid;
  margin-top: 15px;
  display: -webkit-box;
  line-height: 40px;
}
.latest {
  width: 38px;
  height: 18px;
  background-color: #8bc118;
  border-radius: 0 3px 3px 0;
  margin-top: 12px;
  line-height: 18px;
  text-align: center;
  font-size: 12px;
  color: #fff;
}
.chapter {
  width: 66%;
  font-family: "微软雅黑";
  font-size: 14px;
  margin-left: 5px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.time_hoe {
  position: absolute;
  right: 10px;
  font-size: 10px;
  color: #9f9f9f;
}
/* 简介 */
.mulu_lists {
  background: #fff;
  margin-top: 10px;
  padding-top: 10px;
  padding-bottom: 1px;
}

.janjie {
  margin-right: 20px;
  margin-left: 20px;
  font-size: 12px;
  line-height: 23px;
  padding: 10px;
  .synopsis {
    overflow: hidden;
    text-overflow: ellipsis;
    display: -webkit-box;
    -webkit-line-clamp: 4;
    -webkit-box-orient: vertical;
  }
}
.migu {
  font-size: 10px;
  color: #9f9f9f;
  line-height: 24px;
}

/* 页脚 */
.footer {
  position: relative;
  .bac-top {
    position: fixed;
    top: 80%;
    right: 15px;
    width: 75px;
    height: 75px;
    background-size: 100%;
  }
}
</style>